package edu.tgc.web.controller.code;

import java.util.List;
import java.util.Map;

import org.abyss.common.web.controller.easyui.EasyuiResultBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import edu.tgc.custom.EasyuiPageForm;
import edu.tgc.custom.EasyuiSort;
import edu.tgc.entity.code.TbCodeJbType;
import edu.tgc.service.code.CodeService;

@Controller
@RequestMapping(value = "code/jbType")
public class JbTypeController {
    @Autowired
    private CodeService service;

    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(Integer id) {
        this.service.deleteJbTypeById(id);
        return EasyuiResultBuilder.buildAjaxResult("加班类型删除成功", true, true);
    }

    @RequestMapping(value = "/combox")
    @ResponseBody
    public Object findAll() {
        List<Map<String, Object>> list = this.service.findAllJbType();
        return list;
    }

    @RequestMapping(value = "/page")
    @ResponseBody
    public Object getJbTypeListPage(EasyuiPageForm pageForm, EasyuiSort sort) {
        PageRequest pageRequest = pageForm.buildPageRequest(sort.buildSort());
        Page<TbCodeJbType> page = this.service.getJbTypePage(pageRequest);
        return EasyuiResultBuilder.buildDataGridResult(page);
    }

    @RequestMapping(value = "/create")
    public String gotoCreate() {
        return "code/jbType/create";
    }

    @RequestMapping(value = "/manage", method = RequestMethod.GET)
    public String gotoJbTypeList() {
        return "code/jbType/manage";
    }

    @RequestMapping(value = "/update")
    public String gotoUpdate(Integer id, ModelMap map) {
        TbCodeJbType jbType = this.service.findJbTypeById(id);
        map.put("model", jbType);
        return "code/jbType/create";
    }

    @RequestMapping(value = "/save")
    @ResponseBody
    public Object jbTypeSave(TbCodeJbType jbType) {
        this.service.jbTypeSave(jbType);
        return EasyuiResultBuilder.buildAjaxResult("加班类型增加成功", true, true);
    }

    /*    @RequestMapping(value = "/combo")
    @ResponseBody
    public Object combo() {
        List<Map<String, Object>> tree = service.getXmTypeComboTree();
        return tree;
    }*/
}
